﻿using System;
using System.Collections.Generic;
using System.Web;

/// <summary>
/// Summary description for Collector
/// </summary>

namespace CookieFreeAnalyticsCollector
{
   
    #region Class for Inbound Visitor info
    public class VisitorTracked // Inbound data, unprocessed and still in query string.
    {
        // Our private values
        private string vQueryString;
        private string vClientIP;
        private string vUserAgent;
        private string vVisitorID; // This is our made up simple finger print
        private string vRemoteServerIP;
        private string vSessionID;

        // Public access
        public string QueryString   {  get { return vQueryString; }   set { vQueryString = value; }}
        public string ClientIP      {  get { return vClientIP; } set { vClientIP = value; }}
        public string UserAgent     {  get { return vUserAgent; } set { vUserAgent = value; }}
        public string VisitorID { get { return vVisitorID; } set { vVisitorID = value; } }
        public string RemoteServerIP { get { return vRemoteServerIP; } set { vRemoteServerIP = value; } }
        public string ClientSessionID { get { return vSessionID; } set { vSessionID = value; } }

        public VisitorTracked(string querystring, string clientip, string useragent, string visitorid,string remoteserverip, string clientsessionid)
        {
            vQueryString = querystring;
            vClientIP = clientip;
            vUserAgent = useragent;
            vVisitorID = visitorid;
            vRemoteServerIP = remoteserverip;
            vSessionID = clientsessionid;
        }

    }
    #endregion

    /*"utmwv=" + utmVersion +
            "&utmn=" + RandomNumber() +
            "&utmhn=" + HttpUtility.UrlEncode(domainName) +
            "&utmr=" + HttpUtility.UrlEncode(referrer) +
            "&utmp=" + pageurl +
            "&utmul=" + userlang + // User Lang 
            "&utmac=" + CFAGlobal.PropertyID +
            "&utmcc=__utma%3D" + extractGACookieInfo +"%3B" +          
            "&utmvid=" + GADomainHash(sVisitorID); // sVisitorID;
     * 
     * "&utmt=event&utme=5(" + eCategory + "*" + eAction + "*" + eLabel + ")(" + eValue.ToString()+")";
     */

    public class Visit
    {
        private string visitorID; // utmvid
        private string propertyID; // utmac
        private string pageURL; //utmp
        private string referrer; // utmr
        private string userLang; // utmul
        private string clientIP; // Not in query string
        private string userAgent; // Not in query string

        // Will save event logging for the future
        //private string eventType; // utmt (default to page view). utmt=event
        //private string eventCategory; // utme=5(" + eCategory + "*" + eAction + "*" + eLabel + ")(" + eValue.ToString()+")";


    }




    public class CookieFreeCollector
    {
        private static string logging;
        // Set our default capacity to 100 to save it being resized often
        private static List<VisitorTracked> VisitorTrackedInfo = new List<VisitorTracked>(100); 

        public CookieFreeCollector(string querystring, string clientip, string useragent)
        {

        }

        // Add it to our list.
        public static void AddResponse(string inQuery, VisitorTracked tracked)
        {
            VisitorTrackedInfo.Add(tracked);
            // This'll be where we start processing the Response.

            DataLayer.InsertFollow(tracked);
        }

        public static void RemoveResponse(int position)
        {
            // Make sure we are trying to remove an element inside our range
            if (position <= VisitorTrackedInfo.Count)
            {
                VisitorTrackedInfo.RemoveAt(position);
            }
        }




        // Display all the data
        public static string GetResponse()
        {
            string temp = "";
            foreach (VisitorTracked vInfo in VisitorTrackedInfo) // Loop through List with foreach
            {
                temp += "<br/>" + vInfo.VisitorID;
                temp += "<br/>" + vInfo.ClientIP;
                temp += "<br/>" + vInfo.UserAgent;
                temp += " | " + vInfo.QueryString;
                
                
            }
            return temp;
        }
    }


}